<template>
    <div class="wrap">
        <div class="login-wrap">
            <div class="login-title">房屋后台管理</div>
            <div id="darkbannerwrap"></div>
            <el-select v-model="identify" placeholder="请选择登录身份" class="identify-select" size="medium">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <div style="width: 335px;">
              <input type="text" @keyup.enter="login" v-model="account" placeholder="请输入账号">
            </div>
            <div style="width: 335px;">
              <input type="password" @keyup.enter="login"  v-model="password" placeholder="请输入密码">
            </div>
            <!-- <div class="login-tips">
                <router-link to="/rechargePassword">修改密码？</router-link>
            </div> -->
             <div class="login-button">
                <input class="btn btn-primary" value="登录"  type="button" @keyup.enter="login" @click="login">
            </div>
        </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js'),
    common = require('../../common.js');
import Vue from 'vue'
import $ from 'jquery'
export default {
    name: 'login',
    data() {
        return {
            account:'',
            password:'',
            identify: 1,
            options: [{
              label: "平台",
              value: 1
            },{
              label: "房东",
              value: 0
            }]
        }
    },
    mounted(){
      $(".el-input input").css({"height": "50px", "line-height": "50px"})
        // window.localStorage.removeItem('jwt');
        // Vue.http.options.headers.jwt = '';
    },
    methods:{
        login(){
             let url = this.identify == 1 ? CONSTANT.URL.ADMIN.LOGIN : CONSTANT.URL.LANDLORDUSER.LOGIN;

             let param = {};
             if (this.identify) {
               param ={
                 'userName':this.account,'password':this.password
               }
             } else {
               param = {
                 'mobile':this.account,'password':this.password
               }
             }
            this.$http.post(url, param, {emulateJSON:true}).then(res => {
                 let data = res.data;
                 if(data.status == 200){
                    this.$message({
                        type: 'success',
                        message: '登录成功!'
                    });
                    if (this.identify == 1) {
                      sessionStorage.setItem('sessionId',data.data.bussData.sessionId);
                      sessionStorage.setItem('manager',this.account);
                      sessionStorage.setItem('identify', 1)

                      setTimeout(()=> {
                        // window.location.reload();
                        this.$router.push('/')
                      }, 1000);
                    } else if(this.identify == 0) {
                      sessionStorage.setItem('sessionId',data.data.bussData);
                      sessionStorage.setItem('identify', 0)
                      let detailUrl = CONSTANT.URL.LANDLORDUSER.DETAIL
                      common.requestAjax(detailUrl, {}, {}, (result) => {
                        sessionStorage.setItem('manager',result.data.bussData.name);
                        setTimeout(()=> {
                          // window.location.reload();
                          this.$router.push('/')
                        }, 1000);
                      })
                    }


                 }
                 else{
                    this.$message({
                         type: 'warning',
                         message:data.msg
                    });
                 }
             }, res => {
                 // error callback
            });

        }
    }
}
</script>

<style lang="scss" scoped>
  /*@import '/static/bootstrap.css';*/
  /*@import '/sys/static/bootstrap.css';*/
.identify-select {
  width: 100%;
  height: 50px;
  margin-bottom: 25px;
  /*.el-input {*/
    /*.el-input__inner {*/
      /*height: 50px;*/
      /*line-height: 50px;*/
    /*}*/
  /*}*/
}
.wrap {
    height:100%;
    background: url(../../images/bg-house.jpeg) no-repeat center;
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-size: cover;
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
    z-index: 999;
}

.login-wrap {
    position:relative;
    top:200px;
    /* margin: 0px auto 0 auto; */
    min-height: 420px;
    max-width: 420px;
    padding: 40px;
    background-color: #ffffff;
    margin-left: 60%;
    margin-right: auto;
    border-radius: 4px;
    /* overflow-x: hidden; */
    box-sizing: border-box;
    .el-select{
        width: 335px!important;
    }

}

.login-title {
    margin: 10px 0 0 -58px;
    padding: 18px 10px 18px 60px;
    background: #21B5CC;
    position: relative;
    color: #fff;
    font-size: 16px;
}

#darkbannerwrap {
    background: url(../../images/aiwrap.png);
    width: 18px;
    height: 10px;
    margin: 0 0 20px -58px;
    position: relative;
}

input[type=text], input[type=file], input[type=password], input[type=email], select {
    border: 1px solid #DCDEE0;
    vertical-align: middle;
    border-radius: 3px;
    height: 50px!important;
    line-height: 50px!important;
    padding: 0px 16px;
    font-size: 14px;
    color: #555555;
    outline: none;
    width:300px!important;
    margin-bottom: 25px;
}

.login-tips {
    margin-top: -15px;
    margin-bottom: 20px;
    text-align: right;
    text-decoration: none;
    color: #1b66c7;
    font-size: 16px;
    cursor: pointer;
}
.login-button input{
    padding: 12px 24px;
    margin: 0px;
    font-size: 18px;
    line-height: 24px;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    width: 100%;
    cursor: pointer;
    color: #ffffff;
    background-color: #21B5CC;
    border-radius: 3px;
    border: none;
}
</style>
